"""
创建和验证token方法
"""

from flask_jwt_extended import create_access_token, create_refresh_token
from flask import current_app


def generate_token(user_id, isKeep):
    """
    根据登录的用户ID, 生成token
    argument id 用户id
    """

    access_token = create_access_token(identity=user_id)
    refresh_token = create_refresh_token(identity=user_id)

    return (
        {
            "accessToken": access_token,
        }
        if not isKeep
        else {
            "accessToken": access_token,
            "refreshToken": refresh_token,
        }
    )
